package hz.mobileproject.pda.presenter;


import android.content.Context;

import com.blankj.utilcode.util.LogUtils;
import com.google.gson.Gson;

import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xdroidmvp.net.XApi;
import hz.mobileproject.pda.entity.request.Request_data;
import hz.mobileproject.pda.entity.response.Response_data;
import hz.mobileproject.pda.network.Api;
import hz.mobileproject.pda.ui.activity.work.DotTimeLineActivity;
import hz.mobileproject.pda.utils.Base64;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/7/11 0011.
 */

public class PCalroll_query extends XPresent<DotTimeLineActivity> {

    private String token;
    private Gson gson;
    private Request_data data;
    private String body_data;
    private RequestBody body;
    private String mrequest_data;

    public PCalroll_query() {
        gson = new Gson();
        data = new Request_data();

    }

    public void getData(String request_data,int type){
        mrequest_data=request_data;
        LogUtils.e(mrequest_data);
        data.setData(Base64.getBase64(request_data));
        body_data=  gson.toJson(data);
        body=RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),body_data);
        token = getV().getApplicationContext().getSharedPreferences("app_login", Context.MODE_PRIVATE).getString("token","");
        getDataBody(body,type);

    }

    private void getDataBody(RequestBody body,int type) {
        switch (type){//  2.1.1	民警基本信息获取

            case 10://2.1.8	获取点名记录
                Api.getGankService().getqueryRcLog(body,token)
                        .compose(XApi.<Response_data>getApiTransformer())
                        .compose(XApi.<Response_data>getScheduler())
                        .compose(getV().<Response_data>bindToLifecycle())
                        .subscribe(new ApiSubscriber<Response_data>() {
                            @Override
                            protected void onFail(NetError error) {
                            }
                            @Override
                            public void onNext(Response_data gankResults) {
                                LogUtils.e(Base64.getFromBase64(gankResults.getData()));
                                String json= Base64.getFromBase64(gankResults.getData());
                                getV().respnose_data(json);
                            }
                        });
                break;

        }


    }

}

